from PyQt6.QtWidgets import  QTabWidget,QWidget,QVBoxLayout,QPushButton,QTreeWidget,QSplitter,QTreeWidgetItem,QMenu
from PyQt6.QtCore import QSize,Qt
from PyQt6.QtGui import QFont
from db.DbmsDao import DbmsDao
from dbms.MysqlDao import MysqlDao
from utils.Logger import LogPrint
from dialog import ModifyDbmsDialog
from views.TableView import TableView

class DbmsRightTabView(QTabWidget):
    def __init__(self, parent,mysql_obj:MysqlDao,db_name,table_name):
        super(DbmsRightTabView, self).__init__(parent)

        # 初始化变量
        self.mysql_obj=mysql_obj
        self.db_name=db_name
        self.table_name=table_name

        self.init_ui()

    def init_ui(self):

        # 创建第一个标签页
        self.tab1 = QWidget()
        self.tab1_layout = QVBoxLayout()
        table_view=TableView(self,self.mysql_obj,self.db_name,self.table_name)
        self.tab1_layout.addWidget(table_view)
        self.tab1.setLayout(self.tab1_layout)
 
        # 创建第二个标签页
        self.tab2 = QWidget()
        self.tab2_layout = QVBoxLayout()
        self.tab2_layout.addWidget(QPushButton("Button2"))
        self.tab2.setLayout(self.tab2_layout)
 
        # 添加标签页
        self.addTab(self.tab1, "表数据")
        self.addTab(self.tab2, "新建query页")

        self.setTabsClosable(True)
        self.tabCloseRequested.connect(self.tab_closed)
        self.tabBar().setTabButton(0,)
 
        # 设置当前标签页
        self.setCurrentIndex(0)

    def tab_closed(self,index):
        self.removeTab(index)